﻿Create function [dbo].[QuoteString] (@str nvarchar(1998)) returns nvarchar(4000) as 
begin
      declare @ret nvarchar(4000), @sq char(1);
      select @sq='''';
      select @ret = replace(@str,@sq,@sq+@sq);
      return (@sq+@ret+@sq);
end